package com.lan.controller;

import com.lan.businessObject.LoginUser;
import com.lan.entity.sys.Menu;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Field;
import java.util.List;

public class BaseController {

    protected final Logger LOGGER = LoggerFactory.getLogger(getClass());

    /**
     * 获取菜单列表.
     *
     * */
    public static List<Menu> getMenuList(){
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        return loginUser.getMenuList();
    }

    /**
     * 获取当前用户.
     *
     * */
    public static LoginUser getLoginUser(){
        return (LoginUser) SecurityUtils.getSubject().getPrincipal();
    }

    /**
     * 判断对象的每个字段是否都有值.
     *
     * */
    public <T> boolean isFullField(T t) throws IllegalAccessException {
        Field[] userFields = t.getClass().getDeclaredFields();
        for (Field field : userFields) {
            field.setAccessible(true);
            if (null == field.get(t)) {
                return false;
            }
        }
        return true;
    }

}
